<?php
declare(strict_types=1);

namespace ServerApp\lib\server\web_socket;

use ServerApp\lib\config\LogConfig;
use ServerApp\lib\memory\Chan;
use ServerApp\lib\process\SProcess;
use ServerApp\lib\util\ServerHelper;

/**
 * Class createWebSocket
 * @package ServerApp\lib\sserver\web_socket
 */
class createWebSocket
{
    private static $instance = null;

    /**
     * createWebSocket constructor.
     * @param IWebSocket $func2
     */
    private function __construct(IWebSocket $func2)
    {
        ServerHelper::init();
        LogConfig::init();
        Chan::getInstance();
        (new SProcess(function() use ($func2){
            WebSocketPush::init($func2);
        }))->start();
        (new SProcess(function() use ($func2){
            (new WebSocket($func2))->run();
        }))->start();
    }

    /**
     * @param IWebSocket $func2
     * @return null|createWebSocket
     */
    public static function getInstance(IWebSocket $func2)
    {
        if (self::$instance === null) {
            self::$instance = new self($func2);
        }
        return self::$instance;
    }
}